<?
require_once 'mods/class_sdp_task.php';
require_once 'lib/jpgraph/src/jpgraph.php';
require_once 'lib/jpgraph/src/jpgraph_gantt.php';

class GanttAddDataFilter {
	var $aFrom=0;
	var $aTo=0;
	var $aPriority=0;
	var $aPerformers=null;
	var $aStatuses=null;

	function __construct() {
		$this->SetFilter(array(0=>false),0,0,0,0);
		$this->aPerformers[0]=false;
	}
	
	function SetFilter($aPerformers,$aFrom,$aTo,$aPriority,$aStatus) {
		$this->aPerformers=$aPerformers;
		$this->aFrom = $aFrom;
		$this->aTo = $aTo;
		$this->aPriority = $aPriority;
		$task=new SdpTask();
		$this->aStatuses[0]=false;
		$this->aStatuses[$task->status_completed]=($aStatus==0);
		$this->aStatuses[$task->status_new]=($aStatus==0);
		$this->aStatuses[$task->status_plans]=($aStatus==0);
		$this->aStatuses[$task->status_in_progress]=($aStatus==0);
		$this->aStatuses[$task->status_passed]=($aStatus==0);
		$this->aStatuses[$task->status_suspended]=($aStatus==0);
		$this->aStatuses[$task->status_deleted]=false;
		$this->aStatuses[$aStatus]=true;
	}
	
	function isValid($aType,$aData) {
		$result = true;
		if ($aType==IS_GANTT_TASK)
		{
			if($result&&$this->aPerformers[0])
			{
				$result=((true === $this->aPerformers[$aData->performer])&&(0!=$aData->performer));
			}
			if($result&&0!=$this->aFrom)
			{
				$result = ((($aData->end_date>=$this->aFrom)&&($aData->end_date<=$this->aTo))||
				          (($aData->start_date<=$this->aTo)&&($aData->start_date>=$this->aFrom)));
			}
			if($result&&0!=$this->aPriority)
			{
				$result = ($this->aPriority == $aData->priority);
			}
			if($result)
			{
				if ( isset($this->aStatuses[$aData->status]) )
				{
					$result=$this->aStatuses[$aData->status];
				}
				else
				{
					$result=$this->aStatuses[0];
				}
			}
		}
		return $result;
	}
}
?>